package com.evenmo.string;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class CollectionTest {
    @Test
    public void testAdd(){
        Collection c=new ArrayList();
        c.add(1);
        System.out.println(c);
        boolean remove = c.remove(1);
        System.out.println(remove);
        System.out.println(c);
c.add(2);
        System.out.println(c);
        c.clear();
        System.out.println(c);
        c.add(1);
        boolean contains = c.contains(1);
        System.out.println(contains);
        boolean empty = c.isEmpty();
        System.out.println(empty);
        int size = c.size();
        System.out.println(size);
        Collection c2=new ArrayList();
        c2.add(2);
        c2.add(3);
        c.addAll(c2);
        System.out.println(c);
        System.out.println(c.size());
        System.out.println(c2);
        System.out.println("是否包含1"+c.contains(1));
        System.out.println("是否包含c2集合："+c.containsAll(c2));

        Object[] objects = c.toArray();

        System.out.println(objects);
        for (Object object : objects) {
            System.out.println(object);
        }

    }
@Test
    public void testIterator(){
     Collection c=new HashSet();
     c.add(1);
     c.add(2);
     c.add(3);
     c.add(1);
    System.out.println(c.size());
    Iterator iterator = c.iterator();
    while (iterator.hasNext()){
        Object next = iterator.next();
        System.out.println(next);
    }
}
}
